﻿using ExpressesClass.KyApi.Base;
using ExpressesClass.KyApi.billPrint.request;
using ExpressesClass.KyApi.billPrint.response;
using ExpressesClass.Model;
using System.Windows.Forms;

namespace ExpressesClass.IPrints
{
    public class KyPrint : IPrint
    {
        //跨越快递参数
        private static string appKey = "";
        private static string appSecret = "";
        private static string customerCode = "";
        private static string platformFlag = "";

        //测试
        //private static string appKey = "";
        //private static string appSecret = "";
        //private static string customerCode = "";
        //private static string platformFlag = "";

        private Kddh kddh;

        public KyPrint(Kddh kddh)
        {
            this.kddh = kddh;
        }

        public void Print(string printer)
        {
            BillPrintReq billPrintReq = new BillPrintReq();

            billPrintReq.customerCode = customerCode;
            billPrintReq.platformFlag = platformFlag;
            billPrintReq.templateSizeType = "0";
            billPrintReq.waybillNumberInfos.Add(new WaybillNumberInfos { waybillNumber = kddh.mailNo });
            billPrintReq.printClientId = printer;
            billPrintReq.printJJcg = 20;
            billPrintReq.printSon = 20;

            KyClient kyClient = new KyClient(appKey, appSecret);

            BillPrintRsp res = kyClient.execute<BillPrintRsp>(billPrintReq);

            if (res.success)
            {
                MessageBox.Show("面单号:" + kddh.mailNo + " ,已发送打印请求.", "提示");
            }
            else if (!res.success && !string.IsNullOrEmpty(res.msg))
            {
                MessageBox.Show("面单号:" + kddh.mailNo + " ," + res.msg, "提示");
            }
            else
            {
                MessageBox.Show("面单号:" + kddh.mailNo + " ,取消快递电子面单失败,请重试.", "提示");
            }
        }
    }
}